package cn.pluss.baselibrary.http;


import com.orhanobut.logger.Logger;

import cn.pluss.baselibrary.http.exception.ApiException;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public abstract class BaseObserver<T> implements Observer<T> {


    @Override
    public void onSubscribe(Disposable d) {
    }

    @Override
    public void onNext(T t) {

    }

    @Override
    public final void onError(Throwable e) {
        if (e instanceof ApiException) {
            Logger.e(e.getMessage() == null ? "" : e.getMessage());
            onError((ApiException) e);
        } else {
            Logger.e(e.getMessage() == null ? "" : e.getMessage());
            onError(ApiException.handleException(e));
        }
    }

    @Override
    public void onComplete() {

    }

    public abstract void onError(ApiException e);
}
